<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['workorder:repairFeeScale:add']">新增
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="repairFeeScaleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="所属小区" align="center" prop="communityName"/>
      <el-table-column label="人工费" align="center" prop="labourCost" >
        <template slot-scope="scope">
          <el-avatar shape="square" size="mini" :src="scope.row.labourCost|imgurl"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="材料费" align="center" prop="materialCost">
        <template slot-scope="scope">
          <el-avatar shape="square" size="mini" :src="scope.row.materialCost|imgurl"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="机械费" align="center" prop="mechanicalFee">
        <template slot-scope="scope">
          <el-avatar shape="square" size="mini" :src="scope.row.mechanicalFee|imgurl"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['workorder:repairFeeScale:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workorder:repairFeeScale:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <RepairFeeScaleForm ref="formRef" :repairProjectId="repairProjectId" @cancel="getList"/>
  </div>
</template>

<script>

  import {listMixin} from "@/utils/mixins/listMixin";
  import {listRepairFeeScale, delRepairFeeScale, exportRepairFeeScale} from "@/api/workorder/repairFeeScale";
  import RepairFeeScaleForm from "./form.vue"

  export default {
    name: "RepairFeeScale",
    components: {RepairFeeScaleForm},
    mixins: [listMixin],
    data() {
      return {
        // 报修收费标准表格数据
        repairFeeScaleList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          repairProjectId: null,
          communityId: null,
          labourCost: null,
          materialCost: null,
          mechanicalFee: null,
        },
      };
    },
    watch:{
      repairProjectId(){
        this.getList();
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询报修收费标准列表 */
      getList() {
        this.loading = true;
        this.queryParams.repairProjectId = this.repairProjectId || -1
        listRepairFeeScale(this.queryParams).then(response => {
          this.repairFeeScaleList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.formRef.show({"type":"ADD"});
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        const id = row.id || this.ids
        const option = {
          "type":"UPDATE",
          "id": id
        }
        this.$refs.formRef.show(option);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除报修收费标准编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRepairFeeScale(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有报修收费标准数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportRepairFeeScale(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    },
    props: {
      repairProjectId: {
        type: String,
      },
    }
  };
</script>
